package com.ac.scum.log.task.mapper.pack;

import com.ac.scum.log.bean.Package;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PackageMapper extends BaseMapper<Package> {

    @Select("select p.*,sp.expiration_time as expiration_time,sp.server_id as server_id from package p inner join server_package sp on sp.package_id = p.id where sp.package_id in (${packageIds}) and sp.expiration_time > now()")
    List<Package> getPackagesBySpecifiedPackageIds(String packageIds);

    @Select("select if(expiration_time>now(),true,false) from server_package where server_id = #{serverId} and package_id = #{packageId}")
    Boolean serverHasPackage(@Param("serverId") Long serverId, @Param("packageId") Long packageId);

    @Select("select player_id from player_package where server_id = #{serverId} and package_id = #{packageId} and expiration_time > now()")
    List<Long> getHasPackagePlayerIds(@Param("serverId") Long serverId, @Param("packageId") Long packageId);
}
